# cd /mnt/d/work/workspace/wasm/wasm-player
# source /mnt/d/dev/emsdk/wsl/emsdk/emsdk_env.sh
echo "Running Emscripten..."
export INIT_MEMORY=134217728
export EXPORTED_FUNCTIONS="['_initH264Decoder', \
    '_initH265Decoder',  \
    '_malloc','_free',  \
    '_closeDecoder', \
    '_addRawVideoFrameData' ,'_addRtpFrameData']"
    #'_getYuvFrame' \
      #'_testDecode', \
export WASM_LIB_DIR=wasm-libs
export SRC_DIR=./src
export DIST_DIR=./dist

rm -rf ${DIST_DIR}/*


emcc   ${SRC_DIR}/dina_decoder.c \
           ${SRC_DIR}/wasm_utils.c \
           ${SRC_DIR}/rtp.c \
     ${WASM_LIB_DIR}/libavformat.a ${WASM_LIB_DIR}/libavcodec.a \
      ${WASM_LIB_DIR}/libavutil.a  ${WASM_LIB_DIR}/libswscale.a \
       -g4 --source-map-base \
    -O3 \
    -I "include" \
    -s WASM=1 \
    -s TOTAL_MEMORY=${INIT_MEMORY} \
    -s ALLOW_MEMORY_GROWTH=1 \
    -s EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS}" \
    -s EXTRA_EXPORTED_RUNTIME_METHODS="['addFunction','ccall','_malloc', '_free']" \
    -s RESERVED_FUNCTION_POINTERS=14 \
    -s FORCE_FILESYSTEM=1 \
    -o ${DIST_DIR}/libdinadecoder.js

    
    # -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s USE_SDL_TTF=2  \
# --source-map-base
    #--preload-file wasm-test/test.h264 \
    #--use-preload-plugins \
#-s TOTAL_MEMORY=${TOTAL_MEMORY} \
 #-s INITIAL_MEMORY=${INIT_MEMORY} \
cp -r h5-player/*  ${DIST_DIR}


mv ${DIST_DIR}/libdinadecoder.* ${DIST_DIR}/js/

echo "Finished Build"
